package com.vdong.common.oauth.common.authorize;

import com.vdong.common.oauth.common.authorize.util.WebUtils;
import com.vdong.kpay.basics.dubbo.result.APIResult;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 刀锋
 * @date : Create in 9:31 2018/6/27
 * @description:
 */
@Component
public class AuthAuthenticationFailureHandler implements AuthenticationFailureHandler {
    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
                                        AuthenticationException exception) throws IOException, ServletException {
        APIResult result = AuthCommon.FAIL_AUTH_PASSWORD_ERROR_RESULT;
        result.data("message", exception.getMessage());
        WebUtils.responseJson(response, result);
        //WebUtils.responseJson(response, AuthCommon.FAIL_AUTH_PASSWORD_ERROR_RESULT);
    }
}
